'use strict';

var gulp = require('gulp'),
    connect = require('gulp-connect'),
    cgiMock = require('connect-cgi-mock');


// enable cross origin request
var cors = function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Headers', '*');
    next();
};

// gulp default, start the server
gulp.task('default', function () {
    connect.server({
        root: 'local',
        port: 3001,
        middleware: function(){
            return [
                cors,
                cgiMock({
                    root: __dirname + '/cgiMock',
                    route: '/api'
                }),
                // cgiMock({
                //     root: __dirname + '/src/cgiMock',
                //     route: '/page'
                // }),
            ]
        }
    });
});
